package com.yr.ryjk.doctorduty.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yr.ryjk.common.ErrorType;
import com.yr.ryjk.common.Pagination;
import com.yr.ryjk.doctorduty.dao.DoctorDutyMapper;
import com.yr.ryjk.doctorduty.entity.DoctorDuty;
import com.yr.ryjk.util.IDGenerator;
import com.yr.ryjk.util.JSONUtil;

@Service
public class DoctorDutyService implements IDoctorDutySerice {

	@Autowired
	private DoctorDutyMapper docDutyMapper;
	
	@Override
	public DoctorDuty getDoctorDutyById(String id)
	{
		return docDutyMapper.selectByPrimaryKey(id);
	}
	@Override 
	public Map<String, Object> getListOfPage(int pageNo, int pageSize,
			String name, String level)
	{

		List<DoctorDuty> list=docDutyMapper.selectOfPage((pageNo-1)*pageSize,pageSize,name,level);
		int count=docDutyMapper.selectCount(name,level);
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("list", list);
		map.put("pagination", new Pagination(pageSize,pageNo,count));
		
		return map;
	}

	@Override
	public Object getListOfApp(String name, String level)
	{					
		return docDutyMapper.selectOfApp(name, level);	
	}

	@Override
	public Map<String, Object> addDoctorDuty(DoctorDuty duty)
	{
		String id=IDGenerator.gen32UUID();
		duty.setId(id);
		docDutyMapper.insert(duty);
		return JSONUtil.getJSON(ErrorType.SUCCESS);
	}

	@Override
	public Map<String, Object> modifyDoctorDutyInfo(DoctorDuty duty)
	{
		docDutyMapper.updateByPrimaryKey(duty);
		return JSONUtil.getJSON(ErrorType.SUCCESS);
	}

	@Override
	public List<DoctorDuty> getAllDuty()
	{
		return docDutyMapper.selectAllDuty();
	}

}
